import React from "react";
import { inject, observer } from "mobx-react";
import { Tools } from "weaver-mobile";
import { withRouter } from "react-router-dom";
import { WrOrg } from "../../../public";
import { observable, toJS } from "mobx";

const getLabel = Tools.getLabel;

/**
 * 下属或组织部门
 */
@inject("planViewStore")
@withRouter
@observer
export default class Org extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.planViewStore;
    }
    componentWillMount() {
        this.init()
    }
    componentWillReceiveProps(nextProps) {
        let type = nextProps.location.search.replace('?', '')
        if (type != this.state.type) {
            this.init(type)
        }

    }
    init = (type) => {
        if (!type) {
            type = this.props.location.search.replace('?', '');
        }
        const { orgTreeStore } = this.props.planViewStore;
        this.setState({ type })
    }

    handleSelect = (id, data, type) => {
        if(this.state.type=='sub'){ //处理人员
            this.store.resourceid=id
            this.store.getPlanView()
            this.props.history.push("/planHome/planView/index")
        }else{
            if(type=='3'){
                this.store.resourceid=id
                this.store.getPlanView()
                this.props.history.push("/planHome/planView/index")
            }
        }

    }
    render() {
        const { orgTreeStore  } = this.store;
        return (
            <WrOrg
                orgStore={orgTreeStore}
                type={this.state.type}
                onSelect={this.handleSelect}
            />
        )
    }

}